Skip to content

[Spring] Require an active scenario before creating beans #1974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2020

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented May 14, 2020

The glue code context does not require an active scenario. As a result
it was possible to create scenario scoped beans that would be shared
(leak) between scenarios.

An example of this is illustrated below. Because this does require
access to the GlueCodeScope it is not possible to do this in
practice.

@Configuration
public static class TestApplicationConfiguration {
    @Bean
    public BeanFactoryPostProcessor beanFactoryPostProcessor(){
        return factory -> factory.registerScope(SCOPE_CUCUMBER_GLUE, new GlueCodeScope());
    }

    @Bean
    public ExampleService service(ScenarioScopedApi api) {
        return new ExampleService(api);
    }

    @Bean
    @Scope(value = SCOPE_CUCUMBER_GLUE)
    public ScenarioScopedApi api() {
        return new ScenarioScopedApi();
    }
}

However without registering the the GlueCodeScope at start up Spring
will complain about missing the cucumber-glue scope rather then
complain about scope not having started or the missing proxy mode.

So to avoid further confusion:

  1. GlueCodeContext will check if the context has been started.
  2. Add a @ScenarioScope annotation that sets the correct proxy mode.
  3. Do some renaming of internal classes
  4. Use a global counter for conversation ids

Related

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • I've added tests for my code.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@mpkorstanje mpkorstanje force-pushed the require-active-scenario branch 4 times, most recently from e800883 to 8fdb224 Compare May 14, 2020 17:28
@coveralls
Copy link

coveralls commented May 14, 2020

Coverage Status

Coverage decreased (-0.01%) to 85.962% when pulling 1495ada on require-active-scenario into b40c4f4 on master.

The glue code context does not require an active scenario. As a result
it was possible to create scenario scoped beans that would be shared
(leak) between scenarios.

An example of this is illustrated below. Because this does require
access to the `GlueCodeScope` it is not possible to do this in
practice.

```java
@configuration
public static class TestApplicationConfiguration {
    @bean
    public BeanFactoryPostProcessor beanFactoryPostProcessor(){
        return factory -> factory.registerScope(SCOPE_CUCUMBER_GLUE, new GlueCodeScope());
    }

    @bean
    public ExampleService service(ScenarioScopedApi api) {
        return new ExampleService(api);
    }

    @bean
    @scope(value = SCOPE_CUCUMBER_GLUE)
    public ScenarioScopedApi api() {
        return new ScenarioScopedApi();
    }
}
```

However without registering the the `GlueCodeScope` at start up Spring
will complain about missing the cucumber-glue scope rather then
complain about scope not having started or the missing proxy mode.

So to avoid further confusion:

1. GlueCodeContext will check if the context has been started.
2. Add a `@ScenarioScope` annotation that sets the correct proxy mode.
3. Do some renaming of internal classes
4. Use a global counter for conversation ids

Related
 - #1970
 - #1667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants